<template>
  <div class="container">
    <img src="@/assets/white_logo.png" alt="logo" class="top-logo" />
    <div class="login-main">
      <div class="form-title">
        <h1>{{ SystemTitle }}</h1>
        <img src="@/assets/err.png" alt="big-logo" class="login-logo" />
      </div>

      <div class="form-main">
        <div class="logo-box">欢迎登录</div>
        <a-form-model
          ref="ruleForm"
          class="form"
          :model="ruleForm"
          :rules="rules"
        >
          <a-form-model-item has-feedback prop="username">
            <a-input
              v-model="ruleForm.username"
              v-focus
              placeholder="请输入用户名"
            >
            </a-input>
          </a-form-model-item>
          <a-form-model-item has-feedback prop="password">
            <a-input
              v-model="ruleForm.password"
              type="password"
              autocomplete="off"
            >
            </a-input>
          </a-form-model-item>
          <a-form-model-item prop="code">
            <a-row :gutter="8" style="margin: 0 -4px">
              <a-col :span="16">
                <a-input
                  placeholder="请输入验证码"
                  v-model="ruleForm.code"
                  autocomplete="off"
                >
                </a-input>
              </a-col>
              <a-col :span="8" style="padding-left: 4px">
                <a-tooltip title="看不清？点击刷新验证码。">
                  <img
                    :src="code"
                    @click="getCode"
                    style="width: 100%;cursor:pointer;height:48px;"
                  />
                </a-tooltip>
              </a-col>
            </a-row>
          </a-form-model-item>

          <div style="margin-bottom:16px">
            <a-checkbox @change="toggleAuto">
              自动登录
            </a-checkbox>
            <a style="float: right">忘记密码</a>
          </div>
        </a-form-model>
        <div class="control">
          <a-button
            :style="{ height: '50px' }"
            type="primary"
            block
            @click="onSubmit"
            size="large"
          >
            登录
          </a-button>
        </div>
        <div class="use-tip">
          <div>
            <span class="text">建议使用</span>
            <img src="~@/assets/login/chrome.png" alt="" class="icon" />
            <span class="text">Chrome、</span>
            <img src="~@/assets/login/firefox.png" alt="" class="icon" />
            <span class="text">火狐、</span>
            <img src="~@/assets/login/safari.png" alt="" class="icon" />
            <span class="text">Safari浏览器</span>
          </div>
          <div>
            <span class="text">或</span>
            <img src="~@/assets/login/360.png" alt="" class="icon" />
            <span class="text">360、</span>
            <img src="~@/assets/login/sougou.png" alt="" class="icon" />
            <span class="text">搜狗、</span>
            <img src="~@/assets/login/qq.png" alt="" class="icon" />
            <span class="text">QQ等浏览器</span>
            <img src="~@/assets/login/fast.png" alt="" class="icon" />
            <span class="text">极速模式</span>
          </div>
        </div>
        <div class="login-mask" v-if="loading">
          <svg viewBox="25 25 50 50" class="circular">
            <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
          </svg>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { SystemTitle } from '@/config';
import { mapGetters } from 'vuex';
import store from '@/store';
export default {
  data() {
    return {
      SystemTitle,
      ruleForm: {},
      rules: {
        username: { required: true, message: '不能为空！' },
        password: { required: true, message: '不能为空！' },
        code: { required: true, message: '不能为空！' },
      },
      loading: false,
      code: '',
    };
  },
  methods: {
    toggleAuto() {},
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          sessionStorage.setItem('Token', 'admin');
          store.dispatch('GetInfo').then(() => {
            this.$router.push('/dashboard');
          });
        }
      });
    },
    getCode() {},
  },
  computed: {
    ...mapGetters(['mobileType']),
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100vw;
  height: 100vh;
  background: url('./../../assets/bg.png') 50% no-repeat;
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  .top-logo {
    position: fixed;
    left: 40px;
    top: 30px;
    height: 50px;
  }
  .login-main {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-evenly;

    .form-title {
      width: 480px;
      height: 560px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      h1 {
        font-size: 32px;
        margin-top: 0;
        margin-bottom: 30px;
        color: #fff;
        font-weight: 400;
        letter-spacing: 3px;
      }
      .login-logo {
        width: 320px;
        height: 400px;
      }
    }
    .form-main {
      width: 480px;
      background: #fff;
      height: 510px;
      border-radius: 6px;
      position: relative;
      .login-mask {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: hsla(0, 0%, 100%, 0.9);
        display: flex;
        align-items: center;
        justify-content: center;
        .circular {
          height: 42px;
          width: 42px;
          animation: loading-rotate 2s linear infinite;
          .path {
            animation: loading-dash 1.5s ease-in-out infinite;
            stroke-dasharray: 90, 150;
            stroke-dashoffset: 0;
            stroke-width: 2;
            stroke: #409eff;
            stroke-linecap: round;
          }
        }
      }
      .logo-box {
        position: relative;
        width: 100%;
        font-weight: 700;
        font-size: 20px;
        color: #4c4c4c;
        letter-spacing: 2px;
        padding: 0 40px;
        margin: 15px 0 20px;
        &::before {
          position: absolute;
          top: 50%;
          left: 24px;
          transform: translateY(-50%);
          content: '';
          width: 4px;
          height: 16px;
          background-color: #3e6bea;
          border-radius: 2px;
          display: block;
        }
      }
      .form {
        padding: 0 40px;
        margin-top: 40px;
        /deep/ .ant-input {
          height: 50px;
          font-size: 14px;
          background-color: #f6f6f6;
          border-radius: 4px;
          margin-bottom: 5px;
          &:focus {
            background: #fff;
          }
        }
      }
      .control {
        width: 100%;
        padding: 0 40px;
        margin-top: 40px;
      }

      .use-tip {
        position: absolute;
        left: 0;
        bottom: 18px;
        width: 100%;
        text-align: center;
        color: #999;
        font-size: 12px;
        div + div {
          margin-top: 3px;
        }
        .text {
          vertical-align: middle;
        }
        .icon {
          width: 15px;
          display: inline-block;
          vertical-align: middle;
        }
      }
    }
  }
}
</style>
